package bch.rocketmq.config;// ThreadPoolConfig.java
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.concurrent.Executor;

@Configuration
public class ThreadPoolConfig {



    @Bean("delayedQueueExecutor")
    public ThreadPoolTaskExecutor delayedQueueExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 设置核心线程数，建议根据消费者数量来定
        executor.setCorePoolSize(5); 
        // 设置最大线程数，通常与核心线程数相同或略大
        executor.setMaxPoolSize(10);
        // 设置队列容量，用于存放待执行的任务
        executor.setQueueCapacity(200);
        // 设置线程名称前缀，便于日志中区分
        executor.setThreadNamePrefix("DelayedQueue-Consumer-");
        // 初始化线程池
        executor.initialize();
        return executor;
    }
}